package org.pangu.client.config;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author zhangyj
 * @date 2021/8/28 12:49
 */
@Configuration
@Slf4j
public class MQProducerConfiguration {

    @Value("${rocketmq.producer.group}")
    private String producerGroup;
    
    @Value("${rocketmq.name.server}")
    private String nameSvr;

    private Integer sendMsgTimeout;

    private Integer retryTimesWhenSendFailed;

    @Bean
    public DefaultMQProducer defaultMQProducer() throws MQClientException {
        DefaultMQProducer defaultMQProducer = new DefaultMQProducer(this.producerGroup);
        defaultMQProducer.setNamesrvAddr(this.nameSvr);
        defaultMQProducer.setInstanceName("xxx");
        defaultMQProducer.start();
        return defaultMQProducer;
    }

}
